package com.example.draggableview;

import com.example.draggableview.DraggableSortLayout.DragListener;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.TextView;

/**
 * 演示可拖拽排序视图的activity
 * 
 * @author lucher
 * 
 */
public class MainActivity extends Activity implements DragListener {

	DraggableSortLayout draggableLayout;// 自定义可拖拽排序视图控件
	TextView tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		draggableLayout = (DraggableSortLayout) this.findViewById(R.id.draggable_sort_layout);
		tv = (TextView) this.findViewById(R.id.tv);

		draggableLayout.setDragListener(this);
		String[] words = { "AAA", "BBB", "CC", "D", "EEE", "FF" };
		draggableLayout.init(1, words);

		DraggableSortLayout draggableLayout2 = (DraggableSortLayout) this.findViewById(R.id.draggable_sort_layout2);
		draggableLayout2.setDragListener(this);
		String[] words2 = { "a a a", "bbb", "cc" };
		draggableLayout2.init(2, words2);

		// test
		int[] result = { 1, 1, 0, 0, 0, 1 };
		draggableLayout.submit(result);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		}
		super.onResume();
	}

	@Override
	public void onDragStart() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onDragEnd(int number, String[] result) {
		// TODO Auto-generated method stub
		int length = result.length;
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < length; i++) {
			builder.append(result[i] + " ");
		}
		tv.setText("number=" + number + ":" + builder.toString());
	}

}
